/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    bool isSubStructure(TreeNode* A, TreeNode* B) {
        if(A==nullptr||B==nullptr)
            return false;
        return recur(A,B)||isSubStructure(A->left,B)||isSubStructure(A->right,B);
    }

    //B是否包含在以A当前根节点
    bool recur(TreeNode* A,TreeNode* B)
    {
        if(B==nullptr)//B已匹配完
            return true;
        if(A==nullptr||A->val!=B->val)//越过A的叶子，匹配失败||A,B值不同
            return false;
        return recur(A->left,B->left)&&recur(A->right,B->right);
    }
};